#ifndef __FAT_DEFS_H__
#define __FAT_DEFS_H__

/*
#include "fat_opts.h"
#include "fat_types.h"
*/

//-----------------------------------------------------------------------------
//			FAT32 Offsets
//		Name				Offset
//-----------------------------------------------------------------------------
//Config
#define FAT_SECTOR_SIZE						512

//Estructura Boot Sector
struct bootsector
{
	unsigned char	jmpboot[3];
	unsigned char	oemname[8];
	unsigned char	bytspersec[2];
	unsigned char	secperclus[1];
	unsigned char	rsvdseccnt[2]; //Cantidad sectores reservados
	unsigned char	numfats[1];
	unsigned char	rootentcnt[2];
	unsigned char	totsec16[2];
	unsigned char	media[1];
	unsigned char	fatsz16[2];
	unsigned char	secpertrk[2];
	unsigned char	numheads[2];
	unsigned char	hiddsec[4];
	unsigned char	totsec32[4];
	unsigned char	fatsz32[4]; //Tamaño


};

// Boot Sector
#define BS_JMPBOOT				0	// Length = 3
#define BS_OEMNAME				3	// Length = 8
#define BPB_BYTSPERSEC			11	// Length = 2
#define BPB_SECPERCLUS			13	// Length = 1
#define BPB_RSVDSECCNT			14	// Length = 2
#define BPB_NUMFATS				16	// Length = 1
#define BPB_ROOTENTCNT			17	// Length = 2
#define BPB_TOTSEC16			19	// Length = 2
#define BPB_MEDIA				21	// Length = 1
#define	BPB_FATSZ16				22	// Length = 2
#define BPB_SECPERTRK			24	// Length = 2
#define BPB_NUMHEADS			26	// Length = 2
#define BPB_HIDDSEC				28	// Length = 4
#define BPB_TOTSEC32			32	// Length = 4


// FAT 32
#define BPB_FAT32_FATSZ32		36	// Length = 4
#define BPB_FAT32_EXTFLAGS		40	// Length = 2
#define BPB_FAT32_FSVER			42	// Length = 2
#define BPB_FAT32_ROOTCLUS		44	// Length = 4
#define BPB_FAT32_FSINFO		48	// Length = 2
#define BPB_FAT32_BKBOOTSEC		50	// Length = 2
#define BS_FAT32_DRVNUM			64	// Length = 1
#define BS_FAT32_BOOTSIG		66	// Length = 1
#define BS_FAT32_VOLID			67	// Length = 4
#define BS_FAT32_VOLLAB			71	// Length = 11
#define BS_FAT32_FILSYSTYPE		82	// Length = 8

//-----------------------------------------------------------------------------
// FAT Types
//-----------------------------------------------------------------------------
#define	FAT_TYPE_FAT12			1
#define	FAT_TYPE_FAT16			2
#define	FAT_TYPE_FAT32			3

//-----------------------------------------------------------------------------
// FAT32 File Attributes and Types
//-----------------------------------------------------------------------------
#define FILE_ATTR_READ_ONLY   	0x01
#define FILE_ATTR_HIDDEN 		0x02
#define FILE_ATTR_SYSTEM 		0x04
#define FILE_ATTR_VOLUME_ID 	0x08
#define FILE_ATTR_DIRECTORY		0x10
#define FILE_ATTR_ARCHIVE  		0x20
#define FILE_ATTR_DEVICE 		0x40
#define FILE_ATTR_UNUSED  		0x80

#define FILE_ATTR_SYSHID		0x06
#define FILE_ATTR_LFN_TEXT		0x0F
#define FILE_HEADER_BLANK		0x00
#define FILE_HEADER_DELETED		0xE5
#define FILE_TYPE_DIR			0x10
#define FILE_TYPE_FILE			0x20


struct fat_dir_entry
{
	unsigned char Name[11];
	unsigned char Attr;
	unsigned char NTRes;
	unsigned char CrtTimeTenth;
	unsigned char CrtTime[2];
	unsigned char CrtDate[2];
	unsigned char LstAccDate[2];
	unsigned short FstClusHI;
	unsigned char WrtTime[2];
	unsigned char WrtDate[2];
	unsigned short FstClusLO;
	unsigned long FileSize;
} ;


#endif
